import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
          title: const Center(
        child: Text("商品列表"),
      )),
      body: MyHomeBody(),
    );
  }
}

class MyHomeBody extends StatefulWidget {
  const MyHomeBody({Key? key}) : super(key: key);

  @override
  State<MyHomeBody> createState() => _MyHomeBodyState();
}

class _MyHomeBodyState extends State<MyHomeBody> {
  int _count = 0;

  @override
  Widget build(BuildContext context) {
    return Center(
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              ElevatedButton(
                onPressed: () => setState(() {
                  _count++;
                }),
                child: const Text("++++"),
              ),
              const SizedBox(width: 10),
              ElevatedButton(
                onPressed: () => setState(() {
                  _count--;
                }),
                child: const Text("----"),
              ),
            ],
          ),
          Text(
            "当前计数：$_count",
            style: TextStyle(fontSize: 20),
          ),
        ],
      ),
    );
  }
}
